package eval.utilities.configuration;

import eval.exceptions.ConfigurationException;
import eval.host.HostCapacityEnum;

//import org.apache.log4j.Logger;

//import eval.experiment.Experiment;

/**
 * 
 * Configuration file containing all the public fields needed to configure the
 * main aspects of the experiment
 * 
 * @author Nicolo' M. Calcavecchia <calcavecchia@elet.polimi.it>
 */
public class ExperimentConfiguration extends Configuration {

	//static Logger LOG = Logger.getLogger(Experiment.class);
	private static ExperimentConfiguration singleton;


	public static boolean writeToImgFile =true;
	

	public boolean resFile;
	public String resFileStr;
	public String demandDistribution;
	public double demandDistributionSTD;
	public int cpuDemandDistributionVal;
	public int memDemandDistributionVal;
	
	
    public double HostRedLine ;
    public double MaxLine ;
    public double MinLine ;
    public int numberOfTickCandidatesForClosing;

	
    
	
	/**
	 * power vs. profit
	 */
	public double powerPercent;
	public double profitPercent;
	
	/**
	 * The goal of the open stack exp. (openstack/openstack+/openstack++) 
	 *  
	 */
	public String openStackCompareGoal;
	public String hostEvaluate;
	
			
	/**
	 * Duration of the experiment in cycles
	 * */
	public int experimentTicks;

	/**
	 * Period between two ongoing optimizations
	 * */
	public int ongoingOptimizationPeriod;
	public int numberOfRelocation;
	/**
	 * Total number of host in the system
	 * */
	public int totalNumberOfHosts;

	/**
	 * Number of initial VMs
	 * */
	public int numberOfInitialVMs;
		
	
	public int incomeOnLoad;
	public int loadCost;
	
	/**
	 * HOST CHARACTERISTICS:
	 * */
	// SMALL
	
	public int smallHostCpuCapacity;
	public int smallHostMemCapacity;
	public int smallHostProbability;
	public int smallHostPowerValue;
	public int smallhostBaseEnergyConsumption;
	public int smallhostPowerOnConsumption;
//	public double smallHostStartUpValue;
//	
//	// MEDIUM
//	public int mediumHostCpuCapacity;
//	public int mediumHostMemCapacity;
//	public int mediumHostProbability;
//	public int mediumHostPowerValue;
//
//	// LARGE
//	public int largeHostCpuCapacity;
//	public int largeHostMemCapacity;
//	public int largeHostProbability;
//	public int largeHostPowerValue;

	/**
	 * VM Configurations
	 * */
	// SMALL
	public int smallVmCpuMin;
	public int smallVmCpuMax;
	public int smallVmMemMin;
	public int smallVmMemMax;
	public int smallVmProb;
	public int smallLifeTimeMin;
	public int smallLifeTimeMax;

	 
//	// MEDIUM
//	public int mediumVmCpuMin;
//	public int mediumVmCpuMax;
//	public int mediumVmMemMin;
//	public int mediumVmMemMax;
//	public int mediumVmProb;
//	public int mediumLifeTimeMin;
//	public int mediumLifeTimeMax;
//
//	// LARGE
//	public int largeVmCpuMin;
//	public int largeVmCpuMax;
//	public int largeVmMemMin;
//	public int largeVmMemMax;
//	public int largeVmProb;
//	public int largeLifeTimeMin;
//	public int largeLifeTimeMax;
//
//	// HIGH CPU
//	public int highCpuVmCpuMin;
//	public int highCpuVmCpuMax;
//	public int highCpuVmMemMin;
//	public int highCpuVmMemMax;
//	public int highVmProb;
//	public int highLifeTimeMin;
//	public int highLifeTimeMax;

	
	public String averageTimeBetweenDeployRequestsDistribution;
	public int averageTimeBetweenDeployRequests;
	public String averageNumberOfRequestedVMsDistribution;
	//this is the average number of vm's at the cloud
	//use by DeployGenerator when we extract the total number of vm's at cloud
	public int averageNumberOfRequestedVMs;
	public double averageNumberOfRequestedVMsSTD;

	// workload
	public int lowPeriodAverageDuration;
	public int highPeriodAverageDuration;
	public double deploySetAverageDurationSTD;
	
	// deploy set duration
	public String deploySetsDurationDistribution;
	public int deploySetAverageDuration;
	

	public String optimizationGoal;

	public int randomSeed;
	
	public boolean enableSaintyCheck;
	
	public String errorLogFilePath;
	
	public String placementLogsPath;
	
	public String CplexInputFilePath;

	
	// ##### CPLEX VARS #####
	
	public int PLACEMENT_WEIGHT;
	public int RED_LINE_WEIGHT;
	public int nbResources;
	
	public int RELOCATION_WEIGHT;
	public int CAPACITY_OVERFLOW_WEIGHT;
	public int loadBalancingActivated;
	public int penaltyOpenHostOnSpot;
	
	
	//input for calculating gradient:
	public int historyWindowLength;
	public double gradientwidth ;
	public double alfaInputForHWalgo;

	public int hostCounter;
	

	public static ExperimentConfiguration getSingleton() {
		if (singleton == null) {
			singleton = new ExperimentConfiguration();
		}
		return singleton;
	}
	
	@Override
	public void loadFromFile(String filename) throws ConfigurationException /*throws ConfigurationException*/ {
		super.loadFromFile(filename);
	}

	public int getStartUpUnitCost(HostCapacityEnum value) {
		switch (value) {
		case SMALL:
			return smallhostPowerOnConsumption;
		default:
			return 0;
		}
	}
	
	public int getBAseUnitCost(HostCapacityEnum value) {
		switch (value) {
		case SMALL:
			return smallhostBaseEnergyConsumption;
		default:
			return 0;
		}
	}
}
